package cc.kigh.framework.handler.mybatis.type;

import cc.kigh.common.core.domain.MayBeUrl;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author gylang
 * data 2022/2/25
 */
public class PrivateUrlTypeHandler extends BaseTypeHandler<MayBeUrl> {


    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, MayBeUrl parameter, JdbcType jdbcType) throws SQLException {
        ps.setString(i, parameter.toString());
    }

    @Override
    public MayBeUrl getNullableResult(ResultSet rs, String columnName) throws SQLException {
        String val = rs.getString(columnName);
        return null != val ? new MayBeUrl(val) : null;
    }

    @Override
    public MayBeUrl getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        String val = rs.getString(columnIndex);
        return null != val ? new MayBeUrl(val) : null;
    }

    @Override
    public MayBeUrl getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        String val = cs.getString(columnIndex);
        return null != val ? new MayBeUrl(val) : null;
    }
}
